package com.example.demo.time;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class GegTomorrow {
    public static void main(String[] args) {
        Date now = new Date(); //获取当前时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String nowStr = sdf.format(now)+" 00:00:00"; //得到今天凌晨时间
        System.out.println(nowStr);
        Calendar calendar = Calendar.getInstance();

        calendar.setTime(now);
        String today = sdf.format(calendar.getTime()); //得到明天的时间
        System.out.println(today.substring(0,8));

        calendar.setTime(now);
        calendar.add(Calendar.DAY_OF_MONTH, +1);//+1今天的时间加一天
        String tomorrow = sdf.format(calendar.getTime()); //得到明天的时间
        System.out.println(tomorrow.substring(0,8));

        calendar.setTime(now);
        calendar.add(Calendar.DAY_OF_MONTH, -1);//-1今天的时间减一天
        String lastDay = sdf.format(calendar.getTime());
        System.out.println(lastDay.substring(0,8));

        //得到当前年分
        calendar.setTime(now);
        String year = sdf.format(calendar.getTime());
        System.out.println(year.substring(0,4));

        //得到去年年份
        calendar.setTime(now);
        calendar.add(Calendar.YEAR, -1);
        String lastYear = sdf.format(calendar.getTime());
        System.out.println(lastYear.substring(0,4));
    }
}
